package com.example.mapper;

import com.example.pojo.Machine;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface MachineMapper {

    //查询所有设备
    @Select("select * from machine")
    public List<Machine> findAll();

    //根据设备编号删除设备
    @Delete("delete from machine where id = #{id}")
    void deleteById(Integer id);

    /**
     * 重置自增主键
     */
    @Update("alter table brand auto_increment = 1")
    void resetAutoIncrement();


    //保存设备
    @Insert("insert into machine (machineID, machineName, lineName, IPAddress, isConnected, create_time, update_time) VALUE (#{machineID}, #{machineName}, #{lineName}, #{IPAddress}, #{isConnected},#{createTime}, #{updateTime})")
    void insert(Machine machine);

    //根据设备编号查询设备
    @Select("select * from machine where id = #{id}")
    Machine getById(Integer id);

    //更新设备
    @Update("update machine set machineID = #{machineID},machineName = #{machineName},lineName = #{lineName},IPAddress = #{IPAddress},update_time = #{updateTime} where machineID = #{machineID}")
    void update(Machine machine);

    //根据设备编号修改isConnected
    @Update("update machine set isConnected = #{isConnected} where id = #{id}")
    void updateIsConnected(Integer isConnected, Integer id);

    //获取所有设备编号和isConnected
    @Select("select machineID,isConnected from machine")
    List<Machine> getAllMachineIDAndIsConnected();

    //获取所有设备isConnected
    @Select("select isConnected from machine")
    List<Machine> getAllIsConnected();

    //根据machineID获取id
    @Select("select id from machine where machineID = #{machineID}")
    Integer getIdByMachineID(String machineID);

    //根据id获取machineID
    @Select("select machineID from machine where id = #{id}")
    String getMachineIDById(Integer id);

}
